<template>
  <header class="flex-middle-center bg-app">
    <div class="header-left" @click="onBack">
      <a>
        <i class="iconfont icon-back"></i>
        <slot name="left"/>
      </a>
    </div>
    <slot/>
    <div class="header-right">
      <slot name="right"/>
      <!--<a class="iconfont icon-circle-dot" @click="invoke('close')" v-if="app && inAppClose"></a>-->
    </div>
  </header>
</template>

<script>
import { back, invoke } from '../../router'

export default {
  name: 'xHeader',
  props: {
    historyBack: Boolean,
    inAppClose: Boolean
  },
  methods: {
    onBack () {
      if (this.historyBack) {
        history.back()
        return
      }
      back()
    },
    invoke
  }
}
</script>

<style lang="scss">
  @import "../../assets/css/theme";
  header {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 1.5rem;
    position: relative;
    height: $header-height;
    color: #fff;
    font-size: 1.2em;
    z-index: 10;
    a {
      line-height: $header-height;
      display: inline-block;
      position: relative;
      padding: 0 1rem;
      &:active {
        opacity: .75;
      }
    }
  }
  .header-left, .header-right {
    transform: translateY(-50%);
    position: absolute;
    top: 50%;
    .iconfont {
      vertical-align: middle;
      font-size: 1.5rem;
    }
  }
  .header-left {
    left: 0;
  }
  .header-right {
    right: 0;
  }
  .fixed-header {
    padding-top: $header-height;
    header {
      position: fixed !important;
      right: 0;
      left: 0;
      top: 0;
    }
  }
  .rule-select {
    font-size: 1rem;
  }
  .rule {
    a {
      display: block;
      border-radius: 3px;
      border: 1px solid $color-grey-light;
      text-align: center;
      padding: .5rem 0;
      margin: .5rem .5rem 0;
    }
    &.on a {
      background: url("../../assets/img/check.png") no-repeat right bottom;
      background-size: 1.5rem;
      border-color: $color-red;
      color: $color-red;
    }
  }
  @media (max-width: 374px) {
    .rule {
      a {margin: .5rem .25rem 0;}
    }
  }

</style>
